package com.ruoyi.produce.base.cost.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.produce.base.cost.domain.CostItemCond;
import com.ruoyi.produce.base.cost.domain.CostItemDomain;
import com.ruoyi.produce.base.cost.service.ICostItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 成本项目
 * 视图层
 */
@RestController
@RequestMapping("/produce/costItem")
@Api(value = "成本项目模块", tags = "成本项目接口")
public class CostItemController extends BaseController {
    @Autowired
    private ICostItemService costItemService;

    /**
     * 获取成本项目列表
     * @param cond 搜索条件
     * @return
     */
    @ApiOperationSupport(includeParameters = {"CostItemCond.costItemName"})
    @ApiOperation(value = "获取成本项目列表",notes = "查询所有成本项目信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CostItemCond cond) {
        startPage();
        List<CostItemDomain> costItemList = costItemService.selectCostItemList(cond);
        return getDataTable(costItemList);
    }

    /**
     * 新增成本项目信息
     * @param costItem
     * @return
     */
    @ApiOperation(value = "新增成本项目信息", notes = "新增成本项目信息")
    @ApiImplicitParam(name = "costItem", value = "新增成本项目信息", dataType = "CostItemDomain")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CostItemDomain costItem) {
        return toAjax(costItemService.insertCostItem(costItem));
    }

    /**
     * 修改成本项目信息
     *
     * @param costItem
     * @return
     */
    @ApiOperation(value = "修改成本项目信息", notes = "修改成本项目信息")
    @ApiImplicitParam(name = "costItem", value = "修改成本项目信息", dataType = "CostItemDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody CostItemDomain costItem) {
        return toAjax(costItemService.updateCostItem(costItem));
    }

    /**
     * 删除成本项目信息
     * 仅修改删除标志位
     *
     * @param costItem
     * @return
     */
    @ApiOperation(value = "删除民族信息", notes = "删除成本项目信息,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody CostItemDomain costItem) {
        return toAjax(costItemService.updateCostItemDeleteFlag(costItem));
    }
}
